package com.prototipo_picshare;

import java.security.Provider;

import android.location.Criteria;
import android.location.Location;
import android.location.LocationListener;
import android.location.LocationManager;
import android.os.Bundle;
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.Toast;
import com.prototipo_picshare.gps.LocationListeer;

public class Prueba_GPS extends Activity implements OnClickListener,LocationListener {
	LocationManager locationManager;
	Button PGPS;
	

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_prueba__gps);
		
	
		
		Toast.makeText(getBaseContext(), "Gps turned on ", Toast.LENGTH_LONG).show();
	  //prueba GPS
	  		PGPS=(Button) findViewById(R.id.BTpruebaGPS);
	  		PGPS.setOnClickListener(this);
	}

	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		// Inflate the menu; this adds items to the action bar if it is present.
		getMenuInflater().inflate(R.menu.prueba__g, menu);
		return true;
	}

	@Override
	public void onClick(View v) {
		
		switch (v.getId()) 
		{
		
			case R.id.BTpruebaGPS:
				 locationManager = (LocationManager) getSystemService(LOCATION_SERVICE);
			     locationManager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, 10, 0, this);
			     locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 10, 0, this);
				    
			     
			     
			break;
		
		}

		
	}

	@Override
	public void onLocationChanged(Location location) {
		
		Double lat,lon;
	     
		try {

		       lat = location.getLatitude ();
		       lon = location.getLongitude ();
		       locationManager.removeUpdates(this);

		       Toast.makeText(getBaseContext(), "latitud: "+lat+"\n longitud: "+lon, Toast.LENGTH_LONG).show();
				
		} catch (Exception e) {

		       Toast.makeText(getBaseContext(), "erro en el GPS", Toast.LENGTH_LONG).show();

		}
	}

	@Override
	public void onProviderDisabled(String provider) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void onProviderEnabled(String provider) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void onStatusChanged(String provider, int status, Bundle extras) {
		// TODO Auto-generated method stub
		
	}

}
